//    Dhammapada
//    Copyright (C) 2007 Sakya
//    sakya_tg@yahoo.it
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#include <pspkernel.h>
#include <pspsdk.h>
#include <stdio.h>
#include <oslib/oslib.h>

#include "about.h"
#include "dhammapada.h"

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Globals:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static int aboutRetValue = 0;
static int exitFlagAbout= 0;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Show about screen:
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int about(struct settings *userSettings){
    char buffer[262];
    char aboutText[1000] = "";

    sprintf(aboutText, "    Dhammapada PSP V. %s\n", VERSION);
    strcat(aboutText, "by Sakya, 2007\nGraphics by bigboss\n\nThis software is ditributed under GNU General Public License, read LICENSE.TXT for details.");
    strcat(aboutText, "\n\nHomepage: http://sakya.altervista.org/new/index.php?mod=none_dhammapadapsp");
    strcat(aboutText, "\nContacts: sakya_tg@yahoo.it");

    sprintf(buffer, "%s/images/pointer.png", userSettings->ebootPath);
    OSL_IMAGE *anim = oslLoadImageFilePNG(buffer, OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
    if (!anim)
        errorLoadImage(buffer);
    oslSetImageRotCenter(anim);
    
    aboutRetValue = -1;
    //Load images:
    sprintf(buffer, "%s/images/bkg_about.png", userSettings->ebootPath);
    OSL_IMAGE *bkg = oslLoadImageFilePNG(buffer, OSL_IN_RAM | OSL_SWIZZLED, OSL_PF_8888);
    if (!bkg)
        errorLoadImage(buffer);

    sprintf(buffer, "%s/images/fontText.oft", userSettings->ebootPath);
    OSL_FONT *fontText = oslLoadFontFile(buffer);
    if (!fontText)
        errorLoadImage(buffer);
    oslSetFont(fontText);
    oslSetBkColor(RGBA(0, 0, 0, 0));
    oslSetTextColor(RGBA(0, 0, 0, 255));
    
    exitFlagAbout = 0;
    while(!osl_quit && !exitFlagAbout){
        oslStartDrawing();
        oslDrawImageXY(bkg, 0, 0);
        oslDrawImageXY(anim, 23, 20 + anim->centerY);
        if (++anim->angle == 360)
            anim->angle = 0;
        
        oslDrawTextBox(20, 20, 350, 210, aboutText, 0);
        oslReadKeys();
        if (osl_keys->pressed.circle || osl_keys->pressed.cross){
            aboutRetValue = MODE_MAINMENU;
            exitFlagAbout = 1;
        }
    	oslEndDrawing();
    	oslSyncFrame();
    	oslAudioVSync();
    }
    //unLoad images:
    oslDeleteImage(bkg);
    oslDeleteImage(anim);
    oslDeleteFont(fontText);
    return aboutRetValue;
}
